const Koa = require('koa');
const app = new Koa();

const serve = require('koa-static');

const config = require('./config')
/* 
    记录错误的日志
*/
const log4js = require("log4js");

log4js.configure({
  appenders: { cheese: { type: "file", filename: "logs/cheese.log" } },
  categories: { default: { appenders: ["cheese"], level: "error" } }
});
 
const logger = log4js.getLogger("cheese");
// logger.error("Cheese is too ripe!");


//错误处理
require('./middlewares').error(app,logger)

//静态文件
app.use(serve(config.staticDir));

//开启路由
require('./controllers')(app);

//模板引擎
const render = require('koa-art-template');
render(app, {
  root: config.templatesDir,
  extname: '.html',
});


//监听
app.listen(config.port,() => {
    console.log(' =====>','server running 8080 ...')
})